//T10081. 查找二叉树
#include <iostream>
using namespace std;
const int MAXN=100;
int data[MAXN+1],lchild[MAXN+1],rchild[MAXN+1];
int n,x,k;
bool search(int r,int x){
    bool found=false;
    if (lchild[r]>0) found=search(lchild[r],x);
    if (!found){
        k++;
        if (data[r]==x) found=true;
    }
    if (!found&&rchild[r]>0) found=search(rchild[r],x);
    return found;
}
int main(){
    cin>>n>>x;
    for(int i=1;i<=n;i++){
        cin>>data[i]>>lchild[i]>>rchild[i];
    }
    k=0;
    search(1,x);
    cout<<k;
}